import matplotlib.pyplot as plt
import numpy as np
from scipy import interpolate

def read_data(filename):
    f=open(filename, "r")
    lines = f.readlines()
    x=[]
    y=[]
    #e=[]
    for i in range(len(lines)):
        x.append(float(lines[i].split(',')[0]))
        y.append(float(lines[i].split(',')[1]))
        #e.append(float(lines[i].split()[2]))
    f.close()
    return x,y

def SplinefitandOut(filename1,filename2,xmin=0.5,xmax=25.01,step = 0.01):
    x,y = read_data(filename1)
    r = np.arange(xmin,xmax,step)
    tck = interpolate.splrep(x, y, s=0, k=3)
    yfit = interpolate.splev(r, tck, der=0)
    fw=open(filename2, 'w+')
    for i in range(len(r)):
        fw.write(' {:e}    {} \n'.format(r[i],yfit[i]))
    fw.close()